export function getItem (key: string, isLocalStorage = false) {
  // isLocalStorage ：   false:sessionStorage   true:localStotage
  const storage = isLocalStorage ? localStorage : sessionStorage
  const value: string | null = storage.getItem(key)
  if (!value) return null
  try {
    return JSON.parse(value)
  } catch (error) {
    return value
  }
}

export function setItem (
  key: string,
  value: object | string,
  isLocalStorage = false
) {
  // isLocalStorage ：   false:sessionStorage   true:localStotage
  const storage = isLocalStorage ? localStorage : sessionStorage
  if (typeof value === 'object') {
    value = JSON.stringify(value)
  }
  storage.setItem(key, value)
}
